<template>
  <el-aside width="auto">
    <el-menu
      :collapse="collapsedStore.isCollapsed"
      :router="true"
      :default-active="route.fullPath"
    >
      <el-menu-item index="/index">
        <el-icon><HomeFilled /></el-icon>
        <span>首页</span>
      </el-menu-item>
      <el-menu-item index="/center">
        <el-icon><Avatar /></el-icon>
        <span>个人中心</span>
      </el-menu-item>
      <el-sub-menu index="user-manage" v-admin>
        <template #title>
          <el-icon><UserFilled /></el-icon>
          <span>用户管理</span>
        </template>
        <el-menu-item index="/user-manage/adduser">添加用户</el-menu-item>
        <el-menu-item index="/user-manage/userlist">用户列表</el-menu-item>
      </el-sub-menu>
      <el-sub-menu index="news-manage">
        <template #title>
          <el-icon><MessageBox /></el-icon>
          <span>新闻管理</span>
        </template>
        <el-menu-item index="/news-manage/addnews">添加新闻</el-menu-item>
        <el-menu-item index="/news-manage/newslist">新闻列表</el-menu-item>
      </el-sub-menu>
      <el-sub-menu index="product-manage">
        <template #title>
          <el-icon><Reading /></el-icon>
          <span>产品管理</span>
        </template>
        <el-menu-item index="/product-manage/addproduct">添加产品</el-menu-item>
        <el-menu-item index="/product-manage/productlist"
          >产品列表</el-menu-item
        >
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script setup name="SideMenu">
import {
  HomeFilled,
  UserFilled,
  Avatar,
  MessageBox,
  Reading,
} from "@element-plus/icons-vue";
import { useCollapsedStore } from "@/stores/uiStore";
import { useRoute } from "vue-router";
import { useUserStore } from "@/stores/userStore";
const userStore = useUserStore();
const vAdmin = {
  mounted(el) {
    if (userStore.userInfo.is_admin !== true) {
      //原生DOM操作删除儿子
      el.parentNode.removeChild(el);
    }
  },
};

const route = useRoute();

const collapsedStore = useCollapsedStore();
</script>

<style scoped>
.el-aside {
  height: 100vh;
}
.el-menu {
  height: 100vh;
}
</style>
